.386
STACK   SEGMENT USE16 STACK  'STACK'
             DB   200 DUP(0)
STACK   ENDS

DATA    SEGMENT USE16  PUBLIC  'DATA'
        BNAME  DB  'CHENKE',0,0
        IN_NAME  DB  10,?,10 DUP(0)
        BPASS  DB  '123456',0
        IN_PWD  DB  6,?,6 DUP(0)
        AUTH  DB  0
        CRLF  DB  0DH,0AH,'$'
        MENU1 DB  '1.LOAD/RELOAD$'
        MENU2 DB  '2.SEARCH GOOD$'
        MENU3 DB  '3.PLACE AN ORDER$'
        MENU4 DB  '4.RECOMMENDED DOGRAM$'
        MENU5 DB  '5.UNFINISHED$'
        MENU6 DB  '6.UNFINISHED$'
        MENU7 DB  '7.UNFINISHED$'
        MENU8 DB  '8.CS$'
        MENU9 DB  '9.EXIT$'

        LEAD1 DB  'IDENTITY:$'
        LEAD2 DB  'GOODNEW:$'

        LEAD3 DB  'PLEASE INPUT A CHOICE$'
        LEAD4 DB  'PLEASE INPUT NAME$'
        LEAD5 DB  'PLEASE INPUT PASSWORD$'
        LEAD6 DB  'PLEASE INPUT GOOD NAME$'

        LEAD7 DB  'THE LOAD MESSAAGE IS WRONG$'
        LEAD8 DB  'LOAD SUCCESSFULLY$'
        LEAD9 DB  'FIND GOOD SUCCESSFULLY$'
        LEADA DB  'NO GOOD$'
        LEADB DB  'WRONG NUMBER$'
        
        ACTUAL DB  10,?,10 DUP(0),0
        GOOD  DB  10,?,10 DUP(0),0
        N EQU  30
        SNAME DB  'SHOP$'
        GA1 DB  'PEN',0DH,6 DUP(0),10
            DW   35,56,70,25,0
        GA2 DB  'BOOK',0DH,5 DUP(0),9
            DW   12,30,25,5,0
        GAN DB  N-2 DUP('TEMPVALUE',0DH,8,15,0,20,30,0,2,0,0,0)
DATA ENDS

CODE  SEGMENT  USE16 PUBLIC  'CODE'
      ASSUME   CS:CODE,DS:DATA,SS:STACK
START:
      MOV AX,DATA
      MOV DS,AX
      MOV BP,0
  
MENU: 
      LEA DX,OFFSET MENU1
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU2
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU3
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU4
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU5
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU6
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

     LEA DX,OFFSET MENU7
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU8
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H

      LEA DX,OFFSET MENU9
      MOV AH,9
      INT 21H
      MOV DL,0AH
      MOV AH,2
      INT 21H
      MOV DL,0DH
      MOV AH,2
      INT 21H
      
      LEA DX,OFFSET LEAD3
      MOV AH,9
      INT 21H
      MOV AH,1
      INT 21H

      CMP AL,'1'
      JZ STATE1

      CMP AL,'2'
      JZ STATE2

      CMP AL,'3'
      JZ STATE3

      CMP AL,'4'
      JZ STATE4

      CMP AL,'5'
      JZ STATE5

      CMP AL,'6'
      JZ STATE6

      CMP AL,'7'
      JZ STATE7

      CMP AL,'8'
      JZ STATE8

      CMP AL,'9'
      JZ STATE9

      CMP AL,'9'
      LEA DX,  LEADB
      MOV AH,9
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H
      JG MENU

      CMP AL,'1'
      LEA DX, LEADB
      MOV AH,9
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H 
      JL MENU

STATE1:
      MOV SI,OFFSET BNAME
      LEA DX, LEAD4
      MOV AH,9
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H
      LEA DX,IN_NAME
      MOV AH,10
      INT 21H
      LEA DX,OFFSET CRLF
      MOV AH,9
      INT 21H

      MOV CX,7
      MOV SI,OFFSET BNAME
      MOV DI,OFFSET IN_NAME+2
      MOV AL,[DI]
      CMP AL,0DH
      JZ  BACK
LOPA1:
      MOV AL,[SI]
      CMP AL,[DI]
      JNZ TOEND
      INC SI
      INC DI
      DEC CX
      CMP CX,0
      JNZ LOPA1
      MOV AL,[DI]
      CMP AL,'0'
      JNZ TOEND

      LEA DX,IN_PWD
      MOV AH,10
      INT 21H
      MOV DI,OFFSET IN_PWD+2
      MOV SI,OFFSET BPASS
      MOV CX,4
LOPA2:
      MOV AL,[SI]
      CMP AL,[DI]
      JNZ TOEND
      INC SI
      INC DI
      DEC CX
      CMP CX,0
      JNZ LOPA2
      MOV AL,[DI]
      CMP AL,'0'
      JNZ TOEND
      MOV AUTH,1
      LEA DX, LEAD8
      MOV AH,9
      INT 21H
      JMP MENU
BACK:
      MOV AUTH,0
      JMP MENU
TOEND:
      LEA DX, LEAD7
      MOV AH,9
      INT 21H
      JMP BACK

STATE2:
            LEA     DX  , LEAD6
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  GOOD
            MOV   AH ,  10
            INT     21H
              
            MOV  SI  , OFFSET GA1
            MOV   DI  , OFFSET GOOD+2
            MOV  CX ,  10
            MOV  BX ,  0
            MOV  DX ,  0
LOPA3:      MOV  AL  ,  [SI]
            CMP   AL  ,  [DI]
            JNZ    TOAGAIN
            INC    SI
            INC    DI
            DEC   CX
            CMP  CX  ,  0
            JNZ    LOPA3
            LEA     DX  , LEAD9
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            MOV  SI ,OFFSET GA1
            MOV DI ,OFFSET GOOD+2
            MOV    CX  ,   -21
            INC    BX
ST1:      
            ADD    CX  ,   21
            DEC    BX
            CMP    BX  ,   0
            JNZ    ST1
            ADD  SI , CX
            MOV  BP, SI
            MOV  DI  ,   OFFSET ACTUAL +2
ST2:      MOV  AX  ,   [SI]
            MOV  [DI],   AX
            ADD  SI  ,   2
            ADD  DI  ,   2
            CMP  AX  ,   0
            JNZ ST2   
            MOV  BYTE PTR [DI] , '$'
            JMP    MENU

TOAGAIN:    
            MOV  SI , OFFSET GA1
            MOV DI ,OFFSET GOOD+2
            INC   BX
            ADD   DX , 21
            ADD  SI , DX
            CMP BX , N
            JNZ    LOPA3
            LEA     DX  , LEADA
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            MOV   BP , 0
            JMP    MENU

STATE3:
            CMP BP  ,  0
            JZ     TOEND2
            MOV  SI  ,  BP
            ADD   SI  ,  17
            MOV  AX ,  [SI]
            INC    AX
            MOV  [SI] , AX
            JMP   STATE4

TOEND2:     
            LEA     DX  ,LEAD9
            MOV   AH ,  9
            INT     21H
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            JMP    MENU

STATE4:
            MOV     SI  , OFFSET  GA1
            MOV     DI  ,   0
            MOV     DX  ,   0

ST3:        
            MOV     AL  ,   [SI+11]
            MOV     AH  ,   [SI+12]
            MOV     BX  ,   128
            IMUL    BX
            MOV     DX  ,   0
            MOV     BL  ,   [SI+13]
            MOV     BH  ,   [SI+14]
            IDIV    BX
            MOV     CX  ,   AX
            MOV     AL  ,   [SI+17]
            MOV     AH  ,   [SI+18]
            MOV     BX  ,   64
            IMUL    BX
            MOV     DX  ,   0
            MOV     BL  ,   [SI+15]
            MOV     BH  ,   [SI+16]
            IDIV     BX
            MOV     DX  ,   AX
            ADD     CX  ,   DX
            MOV     [SI+19] ,   CL
            MOV     [SI+20] ,   CH
            INC      DI
            CMP     DI  ,   N
            JNZ     LOPA4
            JMP     MENU

LOPA4:      
            MOV     SI  , OFFSET  GA1
            MOV     AX  ,   DI
            MOV     DX  ,   0
ST4:      DEC     AX
            ADD     DX  ,   21
            CMP     AX  ,   0
            JNZ     ST4
            ADD     SI  ,   DX
            JMP     ST3

STATE5:
            JMP MENU

STATE6:
            JMP MENU

STATE7:
            JMP MENU

STATE8:
            MOV     CX  ,   CS
            MOV     BX  ,   CX
            AND     BX  ,   0F000H
            SHR     BX  ,   12
            MOV     SI  ,   4
LOPA5:      
            DEC     SI
            CMP     BL  ,   0AH
            JAE     LOPA7
            ADD     BX  ,   30H
LOPA6:      
            MOV     DX  ,   BX
            MOV     AH  ,   2
            INT     21H
            CMP     SI  ,   0
            JNZ     LOPA8
            LEA     DX  ,  CRLF
            MOV   AH ,  9
            INT     21H
            JMP     MENU
LOPA7:      
            ADD     BX  ,   55
            JMP     LOPA6
LOPA8:      
            SHL     CX  ,   4
            MOV     BX  ,   CX
            AND     BX  ,   0F000H
            SHR     BX  ,   12
            JMP     LOPA5

STATE9:
           MOV AH,4CH
           INT 21H

CODE ENDS
          END START